package com.ctbri.gui;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import javax.swing.JFrame;
import javax.swing.JProgressBar;

import com.ctbri.util.SwingConsole;

public class Ex31 extends JFrame {
	private JProgressBar pb = new JProgressBar(0, 100);
	
	public Ex31() {
		add(pb);
		new Thread(new Runnable() {
			private Random random = new Random();
			@Override
			public void run() {
				while(!Thread.interrupted()) {
					int value = pb.getValue();
					int rand = random.nextInt(10);
					try {
						TimeUnit.MILLISECONDS.sleep(value * 10 - rand);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					pb.setValue(value + 5);
				}
			}
		}).start();
	}
	public static void main(String[] args) {
		SwingConsole.run(new Ex31(), 500, 200);
	}

}
